package cn.daniellee.qunrobot;

import cn.daniellee.qunrobot.component.QQAdapter;
import com.mumu.webclient.KQWebClient;

import java.io.*;
import java.net.URI;
import java.util.Properties;

public class KQClient {

	private static KQWebClient kqWebClient;

	public static Properties config = new Properties();;

	public static File listFile;

	private static void runClient() {
		try {
			if (kqWebClient == null) {
				kqWebClient = new KQWebClient(new URI("wx://localhost:25303"));
			}
			kqWebClient.addQQMSGListenner(new QQAdapter(kqWebClient));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("KQ初始化错误");
		}
	}

	public static void main(String[] args) {
		File file = new File("config.properties");
		if (file.exists()) {
			try (InputStream in = new FileInputStream(file)) {
				config.load(in);
			} catch (Exception e) {
				e.printStackTrace();
				return;
			}
			String location = config.getProperty("location");
			if (location != null) {
				listFile = new File(location);
				if (listFile.exists()) {
					runClient();
				} else {
					System.out.println("location配置的文件不存在");
				}
			} else {
				System.out.println("location配置未找到，请配置后重试");
			}
		} else {
			try {
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
			System.out.println("配置文件不存在，已为您创建，请配置后重启");
		}
	}

}
